
class Counter{
    constructor(limit){
        this.limit = limit
    }
    [Symbol.iterator](){
        let count = 1,
        limit = this.limit
        return{
            next(){
                if (count<=limit) {
                    return {done:false,value:count++}
                }else{
                    return {done:true,value:undefined}
                }
            }
        }
    }
}

let counter = new Counter(3)
let counterIterator = counter[Symbol.iterator]()
console.log(counterIterator.next());//{ done: false, value: 1 }
console.log(counterIterator.next());//{ done: false, value: 2 }
console.log(counterIterator.next());//{ done: false, value: 3 }

let counter2 = new Counter(3)
for (const iterator of counter2) {
    console.log(iterator);
}
//1
//2
//3





